
package com.oa.modules.sys.controller;

import com.oa.modules.sys.entity.SysDeptEntity;
import com.oa.modules.sys.entity.SysUserEntity;
import com.oa.modules.sys.service.SysDeptService;
import com.oa.modules.sys.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Controller公共组件
 *
 * @author sunhui
 */
public abstract class AbstractController {

    @Autowired
    protected SysUserService sysUserService;

    @Autowired
    protected SysDeptService sysDeptService;

    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected SysUserEntity getUser() {
        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getUserId() {
        return getUser().getUserId();
    }

    protected String getDeptId() {

        return getUser().getDeptId();
    }

    /**
     * 获取当前用户的部门信息
     *
     * @return SysDeptEntity
     */
    protected SysDeptEntity getDept() {

        return sysDeptService.getById(getUser().getDeptId());
    }

}
